﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OpenKey
{
    public partial class Host : Form
    {
        private List<KeyInfo> _keys = new List<KeyInfo>();

        public Host()
        {
            InitializeComponent();
        }

        private void Host_Load(object sender, EventArgs e)
        {

        }

        private void toolKey_Click(object sender, EventArgs e)
        {
            KeyDialog kd = new KeyDialog();
            if (kd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this._keys.Add(kd.Info);
                listKeys.DataSource = null;
                listKeys.DataSource = this._keys;
            }
        }

        private void toolEditKey_Click(object sender, EventArgs e)
        {
            int index = listKeys.SelectedIndex;
            if (index >= 0)
            {
                KeyDialog kd = new KeyDialog();
                kd.Info = this._keys[index];
                if (kd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    this._keys[index] = kd.Info;
                    listKeys.DataSource = null;
                    listKeys.DataSource = this._keys;
                }
            }
        }

        private void toolNameSearch_Click(object sender, EventArgs e)
        {
            if (toolCriteria.Text != "")
            {
                foreach (KeyInfo k in this._keys)
                {
                    if (k.Name.StartsWith(toolCriteria.Text))
                    {
                        listKeys.SelectedIndex = this._keys.IndexOf(k);
                        break;
                    }
                }
            }
        }
    }
}
